package cn.dm.controller;
import cn.dm.common.Dto;
import cn.dm.common.DtoUtil;
import cn.dm.pojo.DmItemType;
import cn.dm.service.LocalHomeService;
import cn.dm.vo.DmFloorItems;
import cn.dm.vo.DmItemTypeVo;
import cn.dm.vo.HotItemVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

/***
 * 主页Controller
 */
@RestController
@RequestMapping("/api/p/index")
public class HomeController {

    @Resource
    private LocalHomeService localHomeService;
    /***
     * 查询所有节目类型
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/queryAllType",method = RequestMethod.POST)
    public Dto queryAllType() throws Exception {
      List<DmItemTypeVo> dmItemTypeVos= localHomeService.queryAllItemType();
      return DtoUtil.returnDataSuccess(dmItemTypeVos);
    }
    /***
     * 查询横向导航条
     * @return
     */
    @RequestMapping(value = "/queryTransverse",method = RequestMethod.POST)
    public Dto queryTransverse() throws Exception {
        List<DmItemType> dmItemTypeList= localHomeService.queryTransverse();
        return DtoUtil.returnDataSuccess(dmItemTypeList);
    }
    /***
     * 查询首页轮播图
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/queryBanner",method = RequestMethod.POST)
    public Dto queryBanner()throws Exception{
        List<HotItemVo> hotItemVoList= localHomeService.queryBanner();
        return DtoUtil.returnDataSuccess(hotItemVoList);
    }
    /***
     * 查询今日推荐
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/queryTodayRecommend",method = RequestMethod.POST)
    public Dto queryTodayRecommend()throws Exception{
        List<HotItemVo> hotItemVoList= localHomeService.queryTodayRecommend();
        return DtoUtil.returnDataSuccess(hotItemVoList);
    }
    /***
     * 查询即将开售接口
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/queryToSaleItem",method = RequestMethod.POST)
    public Dto queryToSaleItem()throws Exception{
        List<HotItemVo> hotItemVoList= localHomeService.queryToSaleItem();
        return DtoUtil.returnDataSuccess(hotItemVoList);
    }
    /***
     * 查询不同楼层的数据
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/queryFloorItems",method = RequestMethod.POST)
    public Dto queryFloorItems()throws Exception{
        List<DmFloorItems> dmFloorItems= localHomeService.queryFloorItems();
        return DtoUtil.returnDataSuccess(dmFloorItems);
    }
    /***
     * 查询热门节目
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/queryHotItems",method = RequestMethod.POST)
    public Dto queryHotItems(@RequestBody Map<String,Long> params)throws Exception{
        Long itemTypeId=params.get("itemTypeId");
        List<HotItemVo> hotItemVoList= localHomeService.queryHotItems(itemTypeId);
       return DtoUtil.returnDataSuccess(hotItemVoList);
    }
}
